package hamsterteam.hop.model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;

/**
 *
 * @author Chris
 */
@Entity
@NamedQuery(name = "Projet.findAll", query = "SELECT b FROM Projet b")
public class Projet implements Serializable {
    private static final long serialVersionUID = 1L;

    // Identifiant du projet
    @Id
    @Column(name="projId")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    // Etudiants participant au projet
    @ManyToMany(mappedBy="projets")
    private List<Etudiant> etudiants = new LinkedList<Etudiant>();

    // Responsable du projet
    @ManyToOne
    @JoinColumn(name="ensId")
    private Enseignant responsable;

    private String nom;
    
    private String lien;
    
    public enum Annee
    {
        IRM3,
        IRM4,
        IRM5
    };
    
    @Enumerated(EnumType.STRING)
    private Annee annee;
    
    @Enumerated(EnumType.STRING)
    @Column(name="opt")
    private Etudiant.Option option;

    @Column(length = 2000)
    private String description;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Etudiant> getEtudiants() {
        return etudiants;
    }

    public void setEtudiants(List<Etudiant> etudiants) {
        this.etudiants = etudiants;
    }

    public Enseignant getResponsable() {
        return responsable;
    }

    public void setResponsable(Enseignant responsable) {
        this.responsable = responsable;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Annee getAnnee() {
        return annee;
    }

    public void setAnnee(Annee annee) {
        this.annee = annee;
    }

    public Etudiant.Option getOption() {
        return option;
    }

    public void setOption(Etudiant.Option option) {
        this.option = option;
    }

    public String getLien() {
        return lien;
    }

    public void setLien(String lien) {
        this.lien = lien;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Projet)) {
            return false;
        }
        Projet other = (Projet) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "hamsterteam.hop.entities.Projet[ id=" + id + " ]";
    }

}
